﻿using System.Windows;
using System.Windows.Controls;

namespace Listas
{
    public class Controls : CommomFunctions.Controls
    {
        /// <summary>
        /// elements -> each element in the list is represented by a label with colored background and border
        /// myArrows -> the arrows that represent the link between nodes in a list
        /// memory -> a group of Labels that "simulates" a system memory
        /// myImages -> all the images that will be used during the program execution 
        /// myCbs -> the ComboBoxes that will contain the information about the k-positons where the node can be inserted or removed 
        /// myAnimations -> the objects and functions that will be used to animate the operations
        /// </summary>
        protected static Labels elements = new Labels();
        protected static Arrows myArrows = new Arrows();
        protected static Memory memory = new Memory();
        protected static Images myImages = new Images();
        protected static ComboBoxes myCbs = new ComboBoxes();
        protected static Animations myAnimations = new Animations();

        /// <summary>
        /// Adds to "gridi" the controls that were not declared/created in the xaml file.
        /// </summary>        
        public void addOtherControls(Grid Gridi, ControlVariables cv)
        {
            gd = Gridi;

            myArrows.createArrows(gd);
            elements.createElements(gd);
            myCbs.createComboBoxes(gd);
            memory.createMemory(gd);
            myImages.createControlImages(gd);
            myAnimations.createAnimations(gd, cv);
   
            createTrace(3, 3, 2, 4, new Thickness(25, 75, 0, 10), 290, 265);
            txtTrace.txtTrace.HorizontalAlignment = HorizontalAlignment.Center;

            createLogo(7, 2, new Thickness(0, 30, 36, 15));

            createTitle("Manipulação de Listas Simplesmente Encadeadas", 0, 7, new Thickness(25, 15, 0, 0));
            ((Label)gd.Children[gd.Children.Count - 1]).FontSize = 28;
        }

        /// <summary>
        /// Calls a function that will set the visibility and margins of the images and arrows
        /// </summary>
        /// <param name="cv"></param>
        public void gridSizeChanged(ControlVariables cv)
        {
            cv.rebuild();
        }
        
        /// <summary>
        /// Calls the respective button function
        /// </summary>
        /// <param name="bc"></param>
        /// <param name="cv"></param>
        public void buttonClicked(ButtonClicked bc, ControlVariables cv)
        {
            switch (bc)
            {
                case ButtonClicked.Create: Buttons.btnCria_Click(btns, cv);
                    break;
                case ButtonClicked.Destroy: Buttons.btnDestroi_Click(btns, cv);
                    break;
                case ButtonClicked.InsertAt: Buttons.btnInsertAt_Click(myCbs, cv);
                    break;
                case ButtonClicked.InsertFirst: Buttons.btnInsertFirst_Click(cv);
                    break;
                case ButtonClicked.InsertLast: Buttons.btnInsertLast_Click(cv);
                    break;
                case ButtonClicked.RemoveAt: Buttons.btnRemoveAt_Click(myCbs, cv);
                    break;
                case ButtonClicked.RemoveFirst: Buttons.btnRemoveFirst_Click(cv);
                    break;
                case ButtonClicked.RemoveLast: Buttons.btnRemoveLast_Click(cv);
                    break;
            }
        }
    }
}
